/**
 * 数组去重
 * 两个属性相同的对象也认为是重复的
 * @param {Array} arr
 * @return {Array}
 */
function uniqueArray(arr) {
    const result = [];
    outer: for (const item of arr) {
        for (const r of result) {
            if (equal(item, r)) {
                continue outer;
            }
        }
        result.push(item);
    }
    return result;
}

function isPrimitive(val) {
    return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean';
}
function equal (val1, val2) {
    if(isPrimitive(val1) || isPrimitive(val2)) {
        return Object.is(val1, val2);
    }

    const entries1 = Object.entries(val1);
    const entries2 = Object.entries(val2);
    if(entries1.length !== entries2.length) {
        return false;
    }
    for(const [key, value] of entries1) {
        if(!equal(value, val2[key])) {
            return false;
        }
    }
    return JSON.stringify(val1) === JSON.stringify(val2);
}
console.log(uniqueArray([{a: 1}, {a: 1}]))
